package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Courseorder;
import cn.wolfcode.mapper.CourseorderMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ICourseorderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseorderServiceImpl implements ICourseorderService {

    @Autowired
    private CourseorderMapper courseorderMapper;
    @Override
    public void delete(Long id) {
       courseorderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Courseorder courseorder) {
        courseorder.setInputTime(new Date());
        courseorderMapper.updateStatus(courseorder.getCustomer().getId());
       courseorderMapper.insert(courseorder);
    }

    @Override
    public Courseorder selectByPrimaryKey(Long id) {
        return courseorderMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Courseorder> selectAll() {
        return courseorderMapper.selectAll();
    }

    @Override
    public void update(Courseorder courseorder) {
        courseorderMapper.updateByPrimaryKey(courseorder);
    }

    @Override
    public PageInfo<Courseorder> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Courseorder> courseorders = courseorderMapper.queryForList(qo);
        return new PageInfo(courseorders);
    }
}
